<template>
  <up-popup :show="show" @update:show="(val) => emit('update:show', val)" overlay mode="center" :round="10" closeable closeOnClickOverlay @close="handleClose">
    <view class="deduction-records-modal">
      <view class="modal-header">
        <view class="title">自动扣款记录</view>
      </view>
      
      <view class="modal-content">
        <view class="records-list">
          <view class="record-item" v-for="(record, index) in recordsList" :key="index">
            <view class="record-header">
              <view class="location">{{ record.parkingLocation }}</view>
              <view class="status" :class="record.status === '成功' ? 'success' : 'failed'">
                {{ record.status }}
              </view>
            </view>
            
            <view class="record-details">
              <view class="detail-item">
                <text class="label">扣款时间：</text>
                <text class="value">{{ record.deductionTime }}</text>
              </view>
              <view class="detail-item">
                <text class="label">扣款金额：</text>
                <text class="value amount">{{ record.amount }}元</text>
              </view>
              <view class="detail-item">
                <text class="label">停车时长：</text>
                <text class="value">{{ record.parkingDuration }}</text>
              </view>
              <view class="detail-item" v-if="record.status === '失败'">
                <text class="label">失败原因：</text>
                <text class="value error">{{ record.failReason || '余额不足' }}</text>
              </view>
            </view>
          </view>
        </view>
        
        <view class="empty-state" v-if="!recordsList || recordsList.length === 0">
          <text>暂无扣款记录</text>
        </view>
      </view>
      
      <view class="modal-footer">
        <up-button type="default" @click="handleClose">关闭</up-button>
      </view>
    </view>
  </up-popup>
</template>

<script setup lang="ts">
import { defineProps, defineEmits } from 'vue';

// 定义 props
const props = defineProps({
  show: {
    type: Boolean,
    default: false
  },
  recordsList: {
    type: Array,
    default: () => []
  }
});

// 定义 emits
const emit = defineEmits(['update:show', 'close']);

// 处理关闭事件
const handleClose = () => {
  emit('update:show', false);
  emit('close');
};
</script>

<style lang="scss" scoped>
.deduction-records-modal {
  width: 90vw;
  max-height: 80vh;
  background-color: #fff;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  
  .modal-header {
    padding: 20px 20px 10px;
    border-bottom: 1px solid #eee;
    
    .title {
      font-size: 18px;
      font-weight: bold;
      text-align: center;
      color: #333;
    }
  }
  
  .modal-content {
    flex: 1;
    overflow-y: auto;
    max-height: 60vh;
    
    .records-list {
      padding: 15px;
      
      .record-item {
        background-color: #f8f9fa;
        border-radius: 8px;
        margin-bottom: 12px;
        padding: 15px;
        
        .record-header {
          display: flex;
          justify-content: space-between;
          align-items: center;
          margin-bottom: 10px;
          
          .location {
            font-size: 16px;
            font-weight: bold;
            color: #333;
          }
          
          .status {
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 12px;
            
            &.success {
              background-color: #e8f5e8;
              color: #52c41a;
            }
            
            &.failed {
              background-color: #ffebee;
              color: #f44336;
            }
          }
        }
        
        .record-details {
          .detail-item {
            display: flex;
            margin-bottom: 6px;
            
            .label {
              width: 80px;
              color: #666;
              font-size: 14px;
            }
            
            .value {
              flex: 1;
              color: #333;
              font-size: 14px;
              
              &.amount {
                color: #ff4d4f;
                font-weight: bold;
              }
              
              &.error {
                color: #f44336;
              }
            }
          }
        }
      }
    }
    
    .empty-state {
      text-align: center;
      padding: 40px 20px;
      color: #999;
      font-size: 14px;
    }
  }
  
  .modal-footer {
    padding: 15px 20px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: center;
  }
}
</style>